<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
<style type="text/css">
	
</style>
<div class="page-header">
	<h1>
		<a class="a-back" href="<?= admin_url('classes/grade') ?>">
            <i class="fa fa-reply"></i>
        </a>
		<?=$gradeInfo['grade_name']?>&nbsp;&nbsp;班级管理
	</h1>
</div>

<div class="col-xs-12">
	<!-- 和教师权限不可添加，可以添加功能课室 -->
	<?php if((! $rmxSchool['school_from'] || $gradeInfo['school_id'] == 0) && $rmxUser['user_type'] != USER_TYPE_TEACHER): ?>
		<a href="<?=admin_url('classes/classes_edit')?>/<?=$gradeInfo['id']?>" class="btn btn-info">
			<i class="ace-icon fa fa-plus"></i> 新增班级
		</a>
	<?php endif ?>
	<table id="dynamic-table" class="table table-striped table-bordered table-hover" style="margin-top:10px">
		<thead>
			<tr>
				<th>班级名称</th>
				<th>班主任</th>
				<th>所在教室</th>
				<th width="50%">班级格言</th>
				<th>创建时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>

<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	$(function(){

		// 班级表格
		$('#dynamic-table').dt({
			"ajaxUrl": '<?=admin_url('classes/get_class_list')?>/<?=$gradeInfo['id']?>',
			"columns": [
				{"data": function(ret){
	            	return ret.class_name + '<span class="label label-success ml10">'+ ret.typeName +'</span>';
	            }},
	            {"data": function(ret){
	            	return ret.master ? ret.master.realname : ''
	            }},
	            {"data": function(ret){
	            	return ret.classroom ? ret.classroom.classroom_name : ''
	            }},
	            {"data": "class_slogan"},
	            {"data": "createtime"},
	            {"data": function(ret){
					var action = '';
					// 如果是教师权限，只有任课班级的才能修改或删除
					if(ret.role_change) {
						action += '<a class="edit-grade green mr20" href="<?=admin_url('classes/classes_edit')?>/'+ ret.grade_id +'/'+ ret.id +'"><i class="fa fa-edit"></i> 修改</a>';
						if(ret.is_functional == 0) {
							// 非功能课室不可删除
							<?php if(!$rmxSchool['school_from']): ?>
								action += '<a class="text-danger delete-class" href="javascript:" data-id=' + ret.id +  ' data-title=' + ret.class_name + '><i class="fa fa-times"></i> 删除</a>';
							<?php endif ?>
						} else {
							// 功能课室可删除
							action += '<a class="text-danger delete-class" href="javascript:" data-id=' + ret.id +  ' data-title=' + ret.class_name + '><i class="fa fa-times"></i> 删除</a>';
						}

					}
					return action;
	            }},
			]
		});
		// 删除班级
		$("body").on('click', '.delete-class', function() {
			var id = $(this).data('id');
			var title = $(this).data('title');
			var posturl = "<?= admin_url("classes/delete_class_action") ?>";
			var data = {
				'id': id
			};
			layer.confirm('确定删除：' + title + '？', { title:"提示", offset: '160px' }, function(){
				ajax_post(posturl, data, function() {
					// 刷新页面
					window.location.reload();
				});
			});
		});
	})
</script>